#pragma once

#define ITEM_COLOR_DEFAULT	RGB(193,207,220)
#define TAB_COLOR_DEFAULT	RGB(223,233,243)
#define ITEM_COLOR_CALLIN	RGB(157,203,157)
#define ITEM_COLOR_CALLOUT	RGB(163,162,202)


class TabItem
{
public:
	BOOL bClosable;
	COLORREF clrBkgnd;
	UINT nState;
	UINT nCloseState;
	INT nIndex;
	UINT nSelfID;
	CImage imgIcon;
	CString txtTitle;
};

class TabHeaderEx
{
public:
	enum TabWidgetState{
		NORMAL,
		HOVER,
		DOWN,
		SELECTED
	};

	enum MouseKeyFlag{
		MOVE,
		LBUTTONDOWN,
		LBUTTONUP,
		LBUTTONDBCLK
	};

	enum ItemChangedType{
		INSERT,
		SELCHANGED,
		REMOVE
	};
public:
	TabHeaderEx(void);
	~TabHeaderEx(void);

	void SetRect(CRect rect);
	void SetFixedItemWidth(DWORD dwWidth);
	void SetParentHwnd(HWND hWnd);
	void SetBkgndColor(COLORREF clrBkgnd);
	void SetNotifyMessage(UINT nMsg);

	BOOL InsertItem(UINT nID, LPCTSTR lpszTitle, LPCTSTR lpszIcon, UINT nIDInsertAfter = -1, BOOL bClosable = FALSE, COLORREF clrBkgnd = ITEM_COLOR_DEFAULT);
	void RemoveItem(UINT nID);
	BOOL IsItemEmpty(UINT nID);
	void SelectItem(UINT nID);
	void SelectItemByIndex(INT_PTR nIndex);
	BOOL NotifyItemChanged(UINT nType, UINT nID);

	void ResizeAllItems();
	INT_PTR GetItemCount();
	INT_PTR GetItemIndexByID(UINT nID);
	UINT GetItemIDByIndex(INT_PTR nIndex);

	virtual void Render(HDC hDC);
	virtual void DrawBkgnd(HDC hDC, CRect rect);
	virtual void DrawItem(HDC hDC, TabItem* pItem, CRect rect);
	virtual void DrawPrev(HDC hDC, CRect rect);
	virtual void DrawNext(HDC hDC, CRect rect);
	virtual void DrawClose(HDC hDC, CRect rect, UINT nState);

	void UpdateState(CPoint point, int mkf);

protected:
	TabItem* NewItem(UINT nID, LPCTSTR lpszTitle, LPCTSTR lpszIcon, BOOL bClosable/* = FALSE*/);
	TabItem* GetItemByID(UINT nID);
	TabItem* GetItemByIndex(INT_PTR nIndex);

public:
	HWND mhWnd;
	UINT mnSelfID;
	CRect mRect;
	CRect mRectBak;
	UINT mnNotifyMessage;

	CImage mimgBkgnd;
	COLORREF mclrBkgnd;

	CImage mimgCloseNormal;
	CImage mimgCloseHover;
	CImage mimgCloseDown;

	UINT mnPrevState;
	CImage mimgPrevNormal;
	CImage mimgPrevHover;
	CImage mimgPrevDown;

	UINT mnNextState;
	CImage mimgNextNormal;
	CImage mimgNextHover;
	CImage mimgNextDown;

	CImage mimgItemNormal;
	CImage mimgItemHover;
	CImage mimgItemSelected;

	DWORD mdwItemWidth;
	DWORD mdwItemFixedWidth;

	INT_PTR mnSelectedIndex;
	INT_PTR mnFirstShowIndex;
	INT_PTR mnMaxShowItems;

	UINT mnPrevNextWidth;
	UINT mnIconWidth;
	UINT mnCloseWidth;

	CArray<TabItem*> mItems;
};

